import axios from 'axios'
// 创建axios实例
const service = axios.create()
service.defaults.baseURL = 'www.baidu.com'
service.defaults.withCredentials = true
// 添加请求拦截器
service.interceptors.request.use(config => {
  config.headers = {
    'Content-Type': 'application/x-www-form-urlencoded'
  }
  return config
}, error => {
  Promise.reject(error)
})
// 添加respone拦截器
service.interceptors.response.use(
  response => {
    let res = {}
    res.status = response.status
    res.data = response.data
    return res
  },
  error => {
    if (error.response && error.response.status === 404) {
      // router.push('/blank.vue')
    }
    return Promise.reject(error.response)
  }
)
export const http = service
